<?php
namespace Admin\Form;

use Zend\Form\Form;
use Zend\Db\Adapter\AdapterInterface;

class ThoikhoabieuForm extends Form
{
	protected $dbAdapter;
    public function __construct(AdapterInterface $dbAdapter)
    {
		$this->setDbAdapter($dbAdapter);
        // we want to ignore the name passed
        parent::__construct('thoikhoabieu');

        $this->setAttribute('method', 'post');
        $this->add(array(
            'name' => 'id',
            'attributes' => array(
                'type'  => 'hidden',
            ),
        ));

        
		
		$this->add(array(
            'type' => 'select',
            'name' => 'lop',
            'options' => array(
                'label' => 'Lớp',
                'value_options' =>  $this->getOptionsForSelect(),
            ),
            'attributes' => array(
				'id' => 'lop',
				'required' => 'required',
                'value' => '1' //set selected to '1'
            )
        ));
		$this->add(array(
            'type' => 'select',
            'name' => 'thu',
            'options' => array(
                'label' => 'Thứ',
                'value_options' =>  $this->getOptionsForSelect2(),
            ),
            'attributes' => array(
				'id' => 'thu',
				'required' => 'required',
                'value' => '1' //set selected to '1'
            )
        ));
		$this->add(array(
            'type' => 'select',
            'name' => 'tiet',
            'options' => array(
                'label' => 'Tiết',
                'value_options' =>  $this->getOptionsForSelect3(),
            ),
            'attributes' => array(
				'id' => 'tiet',
				'required' => 'required',
                'value' => '1' //set selected to '1'
            )
        ));
		$this->add(array(
            'type' => 'select',
            'name' => 'monhoc',
            'options' => array(
                'label' => 'Môn học',
                'value_options' =>  $this->getOptionsForSelect4(),
            ),
            'attributes' => array(
				'id' => 'monhoc',
				'required' => 'required',
                'value' => '1' //set selected to '1'
            )
        ));
		$this->add(array(
            'type' => 'select',
            'name' => 'giaovien',
            'options' => array(
                'label' => 'Giáo viên',
                'value_options' =>  $this->getOptionsForSelect5(),
            ),
            'attributes' => array(
				'id' => 'giaovien',
				'required' => 'required',
                'value' => '1' //set selected to '1'
            )
        ));
		$this->add(array(
            'type' => 'select',
            'name' => 'namhoc',
            'options' => array(
                'label' => 'Năm học',
                'value_options' =>  $this->getOptionsForSelect6(),
            ),
            'attributes' => array(
				'id' => 'namhoc',
				'required' => 'required',
                
            )
        ));
		
		$this->add(array(
			'type'  => 'radio',
			'name'  => 'hocki',
			'options' => array(
				'value_options' => array(
					'1' => array(
						'label' => 'Học kì 1',
						'value' => '1',
						'selected' => 'selected',
						'attributes' => array(
							'data-item' => '1',
						),
					),
					'2' => array(
						'label' => 'Học kì 2',
						'value' => '2',
						'attributes' => array(
							'data-item' => '2',
						),
					),
				),
				
			),
		));
		$this->add(array(
			'type'  => 'radio',
			'name'  => 'buoi',
			'options' => array(
				'value_options' => array(
					'1' => array(
						'label' => 'Buổi sáng',
						'value' => 'Sáng',
						'selected' => 'selected',
						'attributes' => array(
							'data-item' => '1',
						),
					),
					'2' => array(
						'label' => 'Buổi chiều',
						'value' => 'Chiều',
						'attributes' => array(
							'data-item' => '2',
						),
					),
				),
				
			),
		));

        $this->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'submit',
                'value' => 'Go',
                'id' => 'submitbutton',
            ),
        ));

    }
	
	public function getOptionsForSelect()
    {
        $dbAdapter = $this->getDbAdapter();
        $sql       = 'SELECT t0.id, t0.tenlop FROM lop t0 ORDER BY t0.id ASC';
        $statement = $dbAdapter->query($sql);
        $result    = $statement->execute();
 
        $selectData = array();
 		
        foreach ($result as $res) {
            $selectData[$res['id']] = $res['tenlop'];
        }
 
        return $selectData;
    }
	public function getOptionsForSelect2()
    {
        $dbAdapter = $this->getDbAdapter();
        $sql       = 'SELECT t0.id, t0.tenthu FROM thu t0 ORDER BY t0.id ASC';
        $statement = $dbAdapter->query($sql);
        $result    = $statement->execute();
 
        $selectData = array();
 		
        foreach ($result as $res) {
            $selectData[$res['id']] = $res['tenthu'];
        }
 
        return $selectData;
    }
	public function getOptionsForSelect3()
    {
        $dbAdapter = $this->getDbAdapter();
        $sql       = 'SELECT t0.id, t0.tentiet FROM tiet t0 ORDER BY t0.id ASC';
        $statement = $dbAdapter->query($sql);
        $result    = $statement->execute();
 
        $selectData = array();
 		
        foreach ($result as $res) {
            $selectData[$res['id']] = $res['tentiet'];
        }
 
        return $selectData;
    }
	public function getOptionsForSelect4()
    {
        $dbAdapter = $this->getDbAdapter();
        $sql       = 'SELECT t0.id, t0.tenmonhoc FROM monhoc t0 ORDER BY t0.id ASC';
        $statement = $dbAdapter->query($sql);
        $result    = $statement->execute();
 
        $selectData = array();
 		
        foreach ($result as $res) {
            $selectData[$res['id']] = $res['tenmonhoc'];
        }
 
        return $selectData;
    }
	public function getOptionsForSelect5()
    {
        $dbAdapter = $this->getDbAdapter();
        $sql       = 'SELECT t0.id, t0.tengv FROM giaovien t0 ORDER BY t0.id ASC';
        $statement = $dbAdapter->query($sql);
        $result    = $statement->execute();
 
        $selectData = array();
 		
        foreach ($result as $res) {
            $selectData[$res['id']] = $res['tengv'];
        }
 
        return $selectData;
    }
	public function getOptionsForSelect6()
    {
        
 		$now = date('Y');
		
        $selectData = array();
 		
        for ($i=0;$i<2;$i++) {
            $selectData[($now+$i).' - '.($now+$i+1)] = ($now+$i).' - '.($now+$i+1);
        }
 
        return $selectData;
    }
	public function setDbAdapter(AdapterInterface $dbAdapter)
    {
        $this->dbAdapter = $dbAdapter;

        return $this;
    }

    public function getDbAdapter()
    {
        return $this->dbAdapter;
    }
}
